

#import "PUDTFBView.h"
#define SCREENW     [UIScreen mainScreen].bounds.size.width
@interface PUDTFBView (){
    UIView *contentView;
}
@property (nonatomic,strong) UICollectionView *collectView;
@property (nonatomic,retain) UIView *nohahaAlphaView;
@property (nonatomic)int is_CallType;
@property (nonatomic)int is_reportblack;
@property (nonatomic)int is_chatMore;
@property (nonatomic)int is_contacts;
@property (nonatomic)BOOL isPinned;
@end
@implementation PUDTFBView

- (instancetype)initCPPDTHView{

    if (self = [super init]) {
        self.frame = [UIScreen mainScreen].bounds;
    }
    [self initAppreaence];
    return self;
}

- (instancetype)initCPPDTHViewCallType{
    if (self = [super init]) {
        self.is_CallType=1;
        self.frame = [UIScreen mainScreen].bounds;
    }
    [self initAppreaence];
    return self;
}

- (instancetype)initCPPDTHViewreportblack{
    if (self = [super init]) {
        self.is_reportblack=1;
        self.frame = [UIScreen mainScreen].bounds;
    }
    [self initAppreaence];
    return self;
}

- (instancetype)initCPPDTHViewChatMore{
    if (self = [super init]) {
        self.is_chatMore=1;
        self.frame = [UIScreen mainScreen].bounds;
    }
    [self initAppreaence];
    return self;
}

- (instancetype)initCPPDTHViewContactsIsPinned:(BOOL)isPinned{
    if (self = [super init]) {
        self.is_contacts=1;
        self.isPinned=isPinned;
        self.frame = [UIScreen mainScreen].bounds;
    }
    [self initAppreaence];
    return self;
}



-(void)moreGesture{
    [self dismiss];
}
-(void)nohahaAlphaViewGesture{
    [self dismiss];
}

#pragma mark - initAppreaence
- (void)initAppreaence {
    
    self.nohahaAlphaView = [[UIView alloc]init];
    self.nohahaAlphaView.frame =self.bounds;
    self.nohahaAlphaView.backgroundColor = [UIColor clearColor];
    [self addSubview:self.nohahaAlphaView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(nohahaAlphaViewGesture)];
    self.nohahaAlphaView.userInteractionEnabled=YES;
    [self.nohahaAlphaView addGestureRecognizer:tap];
    
    
    contentView = [[UIView alloc] init];
    contentView.frame=CGRectMake(0, self.frame.size.height, self.frame.size.width, self.frame.size.width*0.517);
    
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:contentView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(20, 20)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = contentView.bounds;
    maskLayer.path = maskPath.CGPath;
    contentView.layer.mask = maskLayer;
    contentView.backgroundColor=[UIColor whiteColor];
   
    [self addSubview:contentView];
    self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.50];
    
    UIButton *button1=[UIButton buttonWithType:UIButtonTypeCustom];
    button1.tag=1001;
    button1.frame=CGRectMake(0, 0, self.frame.size.width, self.frame.size.width*0.16);
    button1.titleLabel.font = [UIFont systemFontOfSize: 16.0];
    [button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [button1 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    [contentView addSubview:button1];
    
    if (self.is_contacts==1) {
        if (self.isPinned==NO) {
            [button1 setTitle:@"置顶会话" forState:UIControlStateNormal];
        }else{
            [button1 setTitle:@"取消置顶" forState:UIControlStateNormal];
        }
       
    }else{
        if (self.is_chatMore==1) {
            [button1 setTitle:@"查看资料" forState:UIControlStateNormal];
        }else{
            if (self.is_reportblack==1) {
                [button1 setTitle:@"举报" forState:UIControlStateNormal];
            }else{
                if(self.is_CallType==1){
                    [button1 setTitle:@"语音通话" forState:UIControlStateNormal];
                }else{
                    [button1 setTitle:@"  发图片" forState:UIControlStateNormal];
                    [button1 setImage:[UIImage imageNamed:@"DTFTP"] forState:UIControlStateNormal];
                }
            }
        }
    }
    
    
    
    
    UIView *xian1=[[UIView alloc]init];
    xian1.backgroundColor = [UIColor colorWithHex:0xF2F2F2];
    xian1.frame=CGRectMake(0, button1.frame.size.height+button1.frame.origin.y, self.frame.size.width, 0.5);
    [contentView addSubview:xian1];
    
    
    UIButton *button2=[UIButton buttonWithType:UIButtonTypeCustom];
    button2.tag=1002;
    button2.frame=CGRectMake(0, xian1.frame.size.height+xian1.frame.origin.y, self.frame.size.width, self.frame.size.width*0.16);
    button2.titleLabel.font = [UIFont systemFontOfSize: 16.0];
    [button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
   
    [button2 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    [contentView addSubview:button2];
    
    if (self.is_contacts==1) {
        [button2 setTitle:@"删除会话" forState:UIControlStateNormal];
    }else{
        if (self.is_chatMore==1) {
            [button2 setTitle:@"拉黑" forState:UIControlStateNormal];
        }else{
            if (self.is_reportblack==1) {
                [button2 setTitle:@"拉黑" forState:UIControlStateNormal];
            }else{
                if(self.is_CallType==1){
                    [button2 setTitle:@"视频通话" forState:UIControlStateNormal];
                }else{
                    [button2 setTitle:@"  发视频" forState:UIControlStateNormal];
                    [button2 setImage:[UIImage imageNamed:@"DTFSP"] forState:UIControlStateNormal];
                }
            }
        }
    }
    
    
    UIView *xian2=[[UIView alloc]init];
    xian2.backgroundColor = [UIColor colorWithHex:0xF2F2F2];
    xian2.frame=CGRectMake(0, button2.frame.size.height+button2.frame.origin.y, self.frame.size.width, 0.5);
    [contentView addSubview:xian2];
    
    UIButton *button3=[UIButton buttonWithType:UIButtonTypeCustom];
    button3.tag=1003;
    button3.frame=CGRectMake(0, xian2.frame.size.height+xian2.frame.origin.y, self.frame.size.width, self.frame.size.width*0.16);
    button3.titleLabel.font = [UIFont systemFontOfSize: 16.0];
    [button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button3 setTitle:@"  取消" forState:UIControlStateNormal];
    [button3 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:button3];
    
}

#pragma mark - Actions
- (void)buttonClicked:(UIButton *)button {
    [self dismiss];
    if(button.tag==1003){
        return;
    }
    int row=0;
    if(button.tag==1001){
        row=0;
    }
    
    if(button.tag==1002){
        row=1;
    }
    
    
    
    if (self.is_contacts==1) {
        if ([self.delegate respondsToSelector:@selector(CPPDTHViewContacts:isPinned:)]) {
            [self.delegate CPPDTHViewContacts:row isPinned:!self.isPinned];
        }
    }else{
        if (self.is_chatMore==1) {
            if ([self.delegate respondsToSelector:@selector(CPPDTHViewChatMore:)]) {
                [self.delegate CPPDTHViewChatMore:row];
            }
        }else{
            if (self.is_reportblack==1) {
                if ([self.delegate respondsToSelector:@selector(CPPDTHViewreportblackSelectIndex:)]) {
                    [self.delegate CPPDTHViewreportblackSelectIndex:row];
                }
            }else{
                if ([self.delegate respondsToSelector:@selector(CPPDTHViewSelectIndex:)]) {
                    [self.delegate CPPDTHViewSelectIndex:row];
                }
            }
        }
    }
   
}

#pragma mark - pickerView出现
- (void)show {
    
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
    [UIView animateWithDuration:0.2 animations:^{
        self->contentView.center = CGPointMake(self.frame.size.width/2, self->contentView.center.y - self->contentView.frame.size.height);

    }];
}

#pragma mark - pickerView消失
- (void)dismiss{
    [self->contentView removeFromSuperview];
    self->contentView=nil;
    [self removeFromSuperview];
    
//    [UIView animateWithDuration:0.1 animations:^{
//        self->contentView.center = CGPointMake(self.frame.size.width/2, self->contentView.center.y + self->contentView.frame.size.height);
//    } completion:^(BOOL finished) {
//        [self removeFromSuperview];
//    }];
}



@end
